<?php
namespace app\api\controller\wsgoods;
class Usermessage extends Base
{
    public function __construct() {
        parent::__construct();
        $this->checkLogin();
    }

    //消息列表
    public function lists(){
        $d = $this->post();
        $rule = [
            'page'=>'require|integer',
            'limit'=>'require|integer',
        ];
        $msg = [
        ];
        check($rule,$msg,$d);
        $map = [];
        $map[] = ["and","user_id","=",$this->userinfo["id"]];
        $w = where($map);
        $order = "order by id desc";
        $sql = "
            select * from user_message
            $w[0] {$order}
        ".limit($d['page'],$d['limit']);
        $rs = $this->db->query($sql,$w[1]);
        foreach($rs as $k => $v){
            $rs[$k]['create_time_name'] = com_time_format($v['create_time']);
        }
        suc($rs);

    }

    //删除
    public function del(){
        $d = $this->post();
        $rule = [
            'id'=>'require|integer',
        ];
        $msg = [
        ];
        check($rule,$msg,$d);
        $rs = $this->db->delete("user_message",$d["id"]);
        if($rs){
            suc();
        }else{
            err("修改失败");
        }
    }

}
